/*
** hashtables_util.c for zappy in /danstoncul/
** 
** Made by nathan vermelle
** Login   <vermel_n@epitech.net>
** 
** Started on  Mon May 28 12:17:58 2012 nathan vermelle
** Last update Mon May 28 16:43:02 2012 nathan vermelle
*/

#include "server.h"

void		pars_input(char **in, t_params *p)
{
   int		i;

   i = 0;
   while (in[++i + 1])
      if (!strcmp(in[i], "-p"))
	 p->port = atoi(in[i + 1]);
      else if (!strcmp(in[i], "-x"))
	 p->width = atoi(in[i + 1]);
      else if (!strcmp(in[i], "-y"))
	 p->heigh = atoi(in[i + 1]);
// stockage des infos pour les teams ? pas encore mis au point 
      else if (!strcmp(in[i], "-n"))
	 printf("TEAM YO YO YO \n");
      else if (!strcmp(in[i], "-c"))
	 p->nb_clients = atoi(in[i + 1]);
      else if (!strcmp(in[i], "-t"))
	 p->time = atoi(in[i + 1]);
      else
	 exit(-1);
}

//Inialisation des parametre d'entree, mis 
void	params_init(char *av[], t_params *p)
{
   p->port = 1234;
   p->width = 40;
   p->heigh = 40;
   p->nb_clients = 1;
   p->time = 50;
/*parser l'input pour recuperer les bonnes infos (PAS ENCORE FAIT) */
   pars_input(av, p);
}

void	build_map(t_map *m, int x, int y)
{
   srand(time(NULL) * 42);
   m->nb_players = 0;
   m->map[x][y].obj.linemate = rand() % 100;
   m->map[x][y].obj.deraumere = rand() % 100;
   m->map[x][y].obj.sibur =  rand() % 100;
   m->map[x][y].obj.mendiane =  rand() % 100;
   m->map[x][y].obj.phiras =  rand() % 100;
   m->map[x][y].obj.thystame =  rand() % 100;
   m->map[x][y].obj.food =  rand() % 100;   
}

void	map_init(t_params *p, t_map *m)
{
   int		acc;
   int		i;

   acc = -1;
   m->map = malloc(sizeof(t_map) * (p->heigh + 1));
   while (++acc < p->heigh)
      m->map[acc] = malloc((sizeof(t_map)) * (p->width + 1));
   m->map[acc] = '\0';
   acc = -1;
   while (++acc < p->heigh)
   {
      i = -1;
      while (++i < p->width)
	 build_map(m, acc, i);
   }
}

void		launch_server(char *av[])
{
   t_data	d;

   params_init(av, &d.params);
   map_init(&d.params, &d.map);
}

int	main(int ac, char *av[])
{
   launch_server(av);
}
